package com.itstyle.seckill.topic.redis.Iservice.serviceImpl;


import com.itstyle.seckill.topic.redis.Iservice.InventoryProductBiz;
import com.itstyle.seckill.topic.redis.common.RedisDAO;
import com.itstyle.seckill.topic.redis.bean.InventoryProduct;
import com.itstyle.seckill.topic.redis.mapper.ProductInventoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: liuwenxiang
 * @Date: 2020/2/23 17:57
 * @Description:
 */
@Service("inventoryProductBiz")
public class InventoryProductBizImpl implements InventoryProductBiz {

    @Autowired
    private RedisDAO redisBiz;
    @Autowired
    private  ProductInventoryMapper mapper;


    @Override
    public void updateInventoryProduct(InventoryProduct inventoryProduct) {
        // TODO Auto-generated method stub
        mapper.updateProductInventory(inventoryProduct);
    }

    @Override
    public InventoryProduct loadInventoryProductByProductId(Integer productId) {
        // TODO Auto-generated method stub
        return mapper.findProductInventory(productId);
    }

    @Override
    public void setInventoryProductCache(InventoryProduct inventoryProduct) {
        redisBiz.set("inventoryProduct:"+inventoryProduct.getProductId(),"inventoryProduct:"+ inventoryProduct.getInventoryCnt());

    }

    @Override
    public void removeInventoryProductCache(Integer productId) {
        redisBiz.delete("inventoryProduct:"+productId);

    }

    @Override
    public InventoryProduct loadInventoryProductCache(Integer productId) {
        // TODO Auto-generated method stub
       // return redisBiz.get("inventoryProduct:"+productId);
        return null;
    }

}

